import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:meal/components/history/history_order.dart';
import 'package:meal/constant/antd_icons.dart';
import 'package:meal/constant/fonts.dart';
import 'package:meal/constant/sizes.dart';
import 'package:meal/route/route.dart';
import 'package:meal/utils/colors.dart';
import 'package:meal/utils/styles.dart';
import 'package:meal/utils/tools.dart';

///
/// 历史订单
///
class FinishOrder extends StatefulWidget {
  const FinishOrder({Key? key}) : super(key: key);

  @override
  State<FinishOrder> createState() => _FinishOrderState();
}

class _FinishOrderState extends State<FinishOrder>
    with SingleTickerProviderStateMixin, AutomaticKeepAliveClientMixin {
  late final TabController _controller;

  final List<String> tabs = ['待评价', '退款成功', '全部'];

  @override
  void initState() {
    _controller = TabController(length: tabs.length, vsync: this);
    super.initState();
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return Scaffold(
      backgroundColor: ColorsUtils.rgba(245, 245, 245),
      appBar: AppBar(
          automaticallyImplyLeading: false,
          centerTitle: true,
          title: Text('历史订单', style: StylesUtils.customTextStyle(fontSize: Sizes.default18)),
          backgroundColor: ColorsUtils.rgba(255, 110, 83, 1),
          elevation: 0,
          actions: [
            IconButton(
                icon: ImageIcon(ToolsUtils.assetImageIcon('date.png')),
                iconSize: Sizes.default18,
                onPressed: () {
                  BrnDateRangePicker.showDatePicker(context,
                      isDismissible: true,
                      minDateTime: DateTime(2019, 01, 01),
                      maxDateTime: DateTime(2030, 12, 30),
                      pickerMode: BrnDateTimeRangePickerMode.date,
                      minuteDivider: 10,
                      pickerTitleConfig: const BrnPickerTitleConfig(titleContent: '选择日期范围'),
                      dateFormat: 'yyyy-MM-dd',
                      initialStartDateTime: DateTime(2020, 06, 21, 11, 00, 00),
                      initialEndDateTime: DateTime(2020, 06, 23, 10, 00, 00),
                      themeData: BrnPickerConfig(
                          titleTextStyle: BrnTextStyle(
                              color: ColorsUtils.parseColorFromHexString(ColorsUtils.color333),
                              fontSize: Sizes.default15,
                              fontWeight: Fonts.w5)), onConfirm: (DateTime startDateTime,
                          DateTime endDateTime, List<int> startList, List<int> endList) {
                    BrnToast.show(
                        'onConfirm: $startDateTime $endDateTime $startList $endList', context);
                  });
                }),
            IconButton(
                icon: const Icon(
                  AntdIcons.search,
                  color: Colors.white,
                ),
                iconSize: Sizes.default18,
                onPressed: () {
                  Get.toNamed(RouteGet.search);
                }),
          ],
          bottom: PreferredSize(
              preferredSize: Size(Get.width, 50),
              child: Container(
                color: Colors.white,
                alignment: Alignment.center,
                child: ToolsUtils.getClientTabBar(tabs, _controller),
              ))),
      body: TabBarView(
        controller: _controller,
        children: tabs
            .asMap()
            .map((key, value) => MapEntry(key, HistoryOrder(status: key)))
            .values
            .toList(),
      ),
    );
  }

  @override
  bool get wantKeepAlive => true;
}
